<?php
/**
 * Created by PhpStorm.
 * User: wk
 * Date: 2018/4/11
 * Time: 12:13
 */

namespace app\admin\controller;


use think\Controller;
use think\Db;
use think\Request;
use think\view;
class Node extends Admincontroller

{
    public function index()
    {
        $result=Db::table('node')
            ->field(['id','name','mname','aname','status'])
            ->select();
//        var_dump($result);die;
        return view('node/index',['data'=>$result]);
    }
    public function addnode()
    {
        return view('node/add');
    }

    public function doaddnode(Request $request)
    {

//        var_dump($request);exit;
        $data=$request->post();
        $info['name'] =$data['name'];
        $info['mname'] =$data['mname'];
        $info['aname'] =$data['aname'];
        $info['status']=$data['status'];
        $result=Db::table('node')
            ->insert($info);
//        var_dump($result);die;
        if (!empty($result)){
            $this->success('添加成功','admin/node/index');
        }else{
            $this->error('添加失败');
        }
    }

    public function nodedel($id)
    {
//        var_dump($id);
        $res=Db::table('node')
            ->where(['id'=>$id])
            ->delete();
//          var_dump($res);
        if ($res){
            $this->success('删除成功','admin/Node/index');
        }else{
            $this->error('删除失败');
        }
    }


    public function nodeedit($id)
    {
        $res=Db::table('node')
            ->field(['name','mname','aname'])
            ->where(['id'=>$id])
            ->find();
//        var_dump($res);
        return view('node/edit',['id'=>$id,'list'=>$res]);
    }
    public function donodeedit($id)
    {
//        var_dump($_POST);
        $data=$_POST;
        $res=Db::table('node')
            ->where(['id'=>$id])
            ->update($data);
//        var_dump($res);
        if ($res){
            $this->success('添加成功','admin/Node/index');
        }else{
            $this->error('添加失败');
        }

    }
}